package com.edu.bhu.admin.util;

import com.edu.bhu.admin.domain.LibLoan;
import com.edu.bhu.common.utils.DateUtils;

import java.util.Date;

/**
 * @author wangweibo
 *
 * @desc loanStatus属性值工具类
 * @date 2022/2/15
 */
public class loanStatusUtil {

    //loanStatus常量
    public static final Long NORMAL_LOAN = 1L;
    public static final Long OVERDUE_NORETURN = 2L;
    public static final Long NORMAL_RETURN = 3L;
    public static final Long OVERDUE_RETURN = 4L;

    //赋予LibLoan中的loanStatus属性值
    public static LibLoan changeStatus(LibLoan libLoan)
    {
        Date preReturnTime = libLoan.getPreReturnTime();//预期归还时间
        Date praReturnTime = libLoan.getPraReturnTime();//实际归还时间
        Date today = DateUtils.getNowDate();//当前时间

        //判断是否已归还
        if(praReturnTime != null)
        {
            //判断是否逾期
            if(Integer.valueOf(DateUtils.getDatePoorDays(praReturnTime,preReturnTime)) > 0){
                libLoan.setLoanStatus(OVERDUE_RETURN);
            } else {
                libLoan.setLoanStatus(NORMAL_RETURN);
            }
        } else {
            //判断是否逾期
            if(Integer.valueOf(DateUtils.getDatePoorDays(today,preReturnTime)) > 0){
                libLoan.setLoanStatus(OVERDUE_NORETURN);
            } else {
                libLoan.setLoanStatus(NORMAL_LOAN);
            }
        }

        return libLoan;
    }


}
